function t(t, r) {
  if (!t && !r) return "";
  if (!t && r) return r;
  if (t && !r) return t;
  var e, n;
  t.length >= r.length ? (e = t, n = r) : (e = r, n = t);
  var o = parseInt(n.length / 2),
    a = e.length - n.length,
    s = "";
  a > 0 && (s += e.substr(0, a));
  for (var g = 0; g < o; g++) {
    for (var u = (parseInt(n.substr(2 * g, 2), 16) ^ parseInt(e.substr(a + 2 * g, 2), 16)).toString(16); u.length < 2;) u = "0".concat(u);
    s += u;
  }
  return s.toUpperCase();
}

function r(t) {
  return ((t = t.toString())[1] ? t : "0" + t) + "";
}

module.exports = {
  hexString2ArrayBuffer: function(t) {
    for (var r = t.length / 2, e = new ArrayBuffer(r), n = new DataView(e), o = 0; o < r; o++) {
      var a = parseInt(t.substr(2 * o, 2), 16);
      n.setUint8(o, a);
    }
    return e;
  },
  arrayBuffer2HexString: function(t) {
    for (var r, e = "", n = new Uint8Array(t), o = 0; o < n.length; o++) {
      for (r = n[o].toString(16); r.length < 2;) r = "0".concat(r);
      e += r;
    }
    return e;
  },
  getBCDTime: function(t, e) {
    void 0 === t && (t = new Date()), void 0 === e && (e = !0);
    var n = t.getFullYear() - 2e3;
    n < 0 && (n = 0);
    var o = t.getMonth() + 1,
      a = t.getDate(),
      s = t.getHours(),
      g = t.getMinutes(),
      u = t.getSeconds();
    if (e) {
      var i = t.getDay();
      return r(n) + r(o) + r(a) + r(i) + r(s) + r(g) + r(u);
    }
    return r(n) + r(o) + r(a) + r(s) + r(g) + r(u);
  },
  stringToHex: function(t) {
    for (var r = "", e = 0; e < t.length; e++) r += t.charCodeAt(e).toString(16);
    return r;
  },
  stringXor: t,
  getSecretEncoding: function(r, e) {
    if (!r || !e) return "";
    var n = e.length,
      o = parseInt(r.length / n);
    console.log("command(" + r.length + ")/secretLength(" + n + ") = " + o);
    var a = "";
    console.log("secretKey(" + e.length + "):" + e);
    for (var s = 0; s < o; s++) {
      var g = r.substr(s * n, n);
      a += t(g, e), console.log("part" + s + ":" + t(g, e));
    }
    var u = r.length % n;
    if (u > 0) {
      console.log("lastCMD:" + r.substr(r.length - u, u)), console.log("lastSecretKey:" + e.substr(0, u));
      var i = t(r.substr(r.length - u, u), e.substr(0, u));
      a += i, console.log("lastPart:" + i);
    }
    return a;
  },
  hexToString: function(t) {
    for (var r = "", e = t.split(","), n = 0; n < e.length; n++) r += e[n].fromCharCode(n);
    return r;
  },
  getRamNumber: function(t) {
    for (var r = "", e = 0; e < t; e++) r += Math.floor(16 * Math.random()).toString(16);
    return r.toUpperCase();
  },
  isContains: function(t, r) {
    var e = t.toUpperCase(),
      n = r.toUpperCase();
    return new RegExp(n).test(e);
  },
  removeBytes: function(t, r) {
    return t.split(r).join("");
  }
};